package edu.tongji.libraryapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class WelcomeActivity extends Activity {

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);

		bindAnimation();
	}

	private void bindAnimation() {
		final TextView startText = (TextView) findViewById(R.id.startText);
		startText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent searchIntent = new Intent();
				searchIntent
						.setClass(WelcomeActivity.this, LoginActivity.class);
				startActivity(searchIntent);
				overridePendingTransition(R.anim.slide_in_left,
						R.anim.slide_out_left);
			}
		});
		startText.setVisibility(View.GONE);

		final ImageView logoView = (ImageView) findViewById(R.id.logoView);
		final TranslateAnimation logoTranslation = new TranslateAnimation(
				logoView.getX(), logoView.getX(), logoView.getY(),
				logoView.getY() - 100);
		logoTranslation.setDuration(1200);
		logoTranslation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(final Animation arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(final Animation arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(final Animation arg0) {
				logoView.clearAnimation();
				logoView.setY(logoView.getY() - 100);
				startText.setVisibility(View.VISIBLE);
			}
		});
		logoView.startAnimation(logoTranslation);
	}
}
